package br.com.rafael.gestorinvestimentos.DAO;

import java.util.Date;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;

import br.com.rafael.gestorinvestimentos.model.Operacao;

public class OperacaoDAO {
	private Session session;
	
	public OperacaoDAO(Session session){
		this.session = session;
	}	
	
	public void insert (Operacao operacao){
		this.session.save(operacao);
	}
	
	public void update (Operacao operacao){
		this.session.merge(operacao);
	}
	
	public void delete (Operacao operacao){
		this.session.delete(operacao);
	}
	
	public Operacao getOperacao (int id){
		return (Operacao) session.load(Operacao.class, id);
	
	}
	
	public Operacao getOperacao (Date data){
		Query q = this.session.createQuery("from Operacao as operacao where operacao.data = :operacaoData").setParameter("operacaoData", data);
		return (Operacao) q.uniqueResult();
	}
	
	public List getList (){
		return this.session.createCriteria(Operacao.class).list();
	}
}
